function $(id) {
    return document.getElementById(id)
}

function checkuser() {
    var user = $("username").value
    var userId = $("user_prompt")
    var reg = /^1\d{10}$/
    if (reg.test(user) == false) {
        userId.innerHTML = "手机号格式错误";
        return false
    } else {
        return true
    }
}

function checkpwd() {
    var pwd = $("pwd").value
    var pwdId = $("pwd_prompt")
    var reg = /^[a-zA-Z0-9]{4,10}$/
    if (reg.test(pwd) == false) {
        pwdId.innerHTML = "密码格式错误";
        return false
    } else {
        return true
    }
}

function checkrepwd() {
    var pwd = $("pwd").value
    var repwd = $("repwd").value
    var repwdId = $("repwd_prompt")
    if (pwd != repwd) {
        repwdId.innerHTML = "两次输入的密码不一致";
        return false
    } else {
        return true
    }
}



function checkAll() {    
    //用户名和密码检测通过
    if (checkuser() && checkpwd() && checkrepwd()) {
        //获取用户名和密码
        var username = $("username").value
        var pwd = $("pwd").value
        var info = {
            username,
            pwd
        }
        localStorage.setItem("info", JSON.stringify(info))
        alert("成功")
        location.href = "./denglu.html"
        return true
    } else {
        return false
    }
}